#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int p(string a){
    int b;
    vector <string> alf(10, "");
    alf[0]="zero";
    alf[1]="one";
    alf[2]="two";
    alf[3]="three";
    alf[4]="four";
    alf[5]="five";
    alf[6]="six";
    alf[7]="seven";
    alf[8]="eight";
    alf[9]="nine";
    for (int i=0; i<10; i++){
        if (a==alf[i]){
            return i;
        }
    }
    return -1;
}
bool is_prime(int a){
    for (int i=2; i<sqrt(a)+1; i++){
        if (a%i==0){
            return false;
        }
    }
    return true;
}
int main()
{
    string a1,a2,a3;
    int b1,b2,b3,b;
    cin >> a1;
    b1=p(a1);
    if (b1==-1){
        cout << "Wrong input";
        return 0;
    }
    cin >> a2;
    b2=p(a2);
    if (b2==-1){
        cout << "Wrong input";
        return 0;
    }
    cin >> a3;
    b3=p(a3);
    if (b3==-1){
        cout << "Wrong input";
        return 0;
    }
    b=b1*100+b2*10+b3;
    int i=0;
    while (true) {
        if (is_prime(b-i)) {
            cout << b-i;
            return 0;
        }
        if (is_prime(b+i)) {
            cout << b+i;
            return 0;
        }
        i+=1;
    }
    return 0;
}